Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: execute template methods directly #11

Merged
merged 6 commits into from
Sep 21, 2023

Conversation

ryan-timothy-albert
Copy link
Collaborator

Allow template methods to be executed directly from easy template

engine.go Outdated
@@ -160,6 +165,61 @@ func (e *Engine) RunScript(scriptFile string, data any) error {
return nil
}

// MethodExecutor returns an execution function that enables calls to global template methods from easytemplate.
func (e *Engine) MethodExecutor(scriptFile string, data any) (func(fnName string, args ...interface{}) (interface{}, error), error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was actually just thinking of having a Run that takes a method name and then someone would call RunScript first followed by Run to run additional methods in the environment setup by RunScript.

That would maybe simplify the implementation here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that but don't we need to do this in RunScript which we don't right now

result := esbuild.Transform(string(script), esbuild.TransformOptions{
Target: esbuild.ES2015,
Loader: esbuild.LoaderTS,
Sourcemap: esbuild.SourceMapExternal,
})

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/speakeasy-api/easytemplate/blob/main/engine.go#L156

I'm not sure what the implications of adding that for every RunScript would be.

Copy link
Member

@TristanSpeakEasy TristanSpeakEasy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preapproving based on the changes we discussed in a call happening

@ryan-timothy-albert ryan-timothy-albert merged commit 4350270 into main Sep 21, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants